import subprocess
import os
import time


def test():
    path = os.getcwd()
    print("os.getcwd()", path)

    list1 = os.listdir(path)
    print("list1", list1)
    for e in list1:
        print(e, type(e))
    # os.mkdir("aa")
    os.makedirs("aa/bbb", exist_ok=True)


def test_mkdirs():
    os.makedirs("mm/nn/dd")


# 仅仅能够删除文件
def test_remove():
    os.remove("mm/nn/dd/a.txt")


def format_time(my_time):
    return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(my_time))


def test_stat():
    info = os.stat("/home/deepin23/dev/bi/superset/superset-frontend/package.json")
    print(info)
    print(type(info))
    print("最后一次访问时间", format_time(info.st_atime))
    print("创建时间", format_time(info.st_ctime))
    print("修改时间", format_time(info.st_mtime))
    print("文件的大小(byte)", info.st_size)
    print("文件的大小(kb)", info.st_size // 1024)


def test2():
    # 删除空目录，非空或者不存在会进行异常的抛出
    # os.rmdir(os.getcwd() + '/a')
    os.removedirs(os.getcwd() + '/aa/')


# 遍历目录
def test3():
    for root, dirs, files in os.walk(os.getcwd()):
        print("root", root)
        print("dirs", dirs)
        print("files", files)
        print("-" * 20)


#
def startfile():
    # 据说仅仅windows ok
    # os.startfile("/opt/apps/cn.wps.wps-office/files/bin/wpspdf")
    # subprocess.Popen(["xdg-open", "/opt/apps/cn.wps.wps-office/files/bin/wpspdf"])
    # subprocess.Popen(["/home/deepin23/Downloads/a.pdf"], executable="/opt/apps/cn.wps.wps-office/files/bin/wpspdf", shell=True)
    subprocess.Popen(["/opt/apps/cn.wps.wps-office/files/bin/wpspdf"],
                     shell=True)


if __name__ == '__main__':
    startfile()
